package io.renren.modules.jxgk.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.jxgk.entity.ClassAttendenceEntity;
import io.renren.modules.jxgk.entity.ClassAttendenceInfoEntity;
import io.renren.modules.jxgk.entity.StudentAttendenceInfoEntity;
import io.renren.modules.jxgk.service.ClassAttendenceInfoService;
import io.renren.modules.jxgk.service.StudentAttendenceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wuwenze.poi.ExcelKit;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("ClassAttendenceInfo/")
public class ClassAttendenceInfoController {

    @Autowired
    ClassAttendenceInfoService classAttendenceInfoService;

    @RequestMapping("Select")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<ClassAttendenceInfoEntity> cse = classAttendenceInfoService.queryList(query);
        int total = classAttendenceInfoService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
    @RequestMapping("selectAttendenceDetails")
    public R selectAttendenceDetails(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<ClassAttendenceEntity> cse = classAttendenceInfoService.selectAttendenceDetails(query);
        int total = classAttendenceInfoService.queryDetailsTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
    @RequestMapping("/export")
    public R export(HttpServletResponse response, @RequestParam Map<String, Object> params) {
        List<ClassAttendenceInfoEntity> cse=null;
        try{
             cse = classAttendenceInfoService.queryList(params);
            ExcelKit.$Export(ClassAttendenceInfoEntity.class, response).toExcel(cse, "班级考勤数据");
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return R.ok();
    }
    @RequestMapping("/exportDetails")
    public R exportDetails(HttpServletResponse response, @RequestParam Map<String, Object> params) {
        List<ClassAttendenceEntity> cse=null;
        try{
            cse = classAttendenceInfoService.selectAttendenceDetails(params);
            ExcelKit.$Export(ClassAttendenceEntity.class, response).toExcel(cse, "班级考勤数据记录");
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return R.ok();
    }
}
